/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 战斗结算数据--单个玩家
	/// module : structs
	/// </summary>
	public class BattleSettlementPOD : IPOD 
    {
        public readonly static Func<BattleSettlementPOD> FACTORY = () => new BattleSettlementPOD();
		public static Func<BattleSettlementPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 战斗类型
        /// </summary>
		public BattleType battleType;
		/// <summary>
        /// 战斗结果
        /// </summary>
		public BattleResultType resultType;
		/// <summary>
        /// 统计数据, 后续改为pod
        /// </summary>
		public BattleStatisticsPOD statisticsPOD;
		/// <summary>
        /// 战斗奖励
        /// </summary>
        private List<ItemShowPOD> m_awards;
		/// <summary>
        /// 测试战斗结算信息, 如果是测试战斗类型才有值
        /// </summary>
		public BattleTestSettlementPOD testSettlementPOD;
		/// <summary>
        /// 关卡战斗结算信息, 如果是关卡战斗类型才有值
        /// </summary>
		public BattleLevelSettlementPOD levelSettlementPOD;
		
		
        public List<ItemShowPOD> awards
        {
            get
            {
                if(m_awards == null)
                {
                    m_awards = new();
                }
                return m_awards;
            }
            private set => m_awards = value;
        }
        public List<ItemShowPOD> unsafe_awards
        {
        	get => m_awards;
        	set => m_awards = value;
        }
		
		/*-- constructors --*/
		public BattleSettlementPOD() {}
		public BattleSettlementPOD(BattleType battleType, BattleResultType resultType, BattleStatisticsPOD statisticsPOD, List<ItemShowPOD> awards, BattleTestSettlementPOD testSettlementPOD, BattleLevelSettlementPOD levelSettlementPOD) {
			this.battleType = battleType;
			this.resultType = resultType;
			this.statisticsPOD = statisticsPOD;
			this.m_awards = awards;
			this.testSettlementPOD = testSettlementPOD;
			this.levelSettlementPOD = levelSettlementPOD;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_byte((sbyte)battleType);
            _out.Write_byte((sbyte)resultType);
            _out.Write_pod(statisticsPOD);
            _out.Write_list_pod(m_awards);
            _out.Write_pod(testSettlementPOD);
            _out.Write_pod(levelSettlementPOD);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            battleType = (BattleType)_in.Read_byte();
            if(!_in.HasRemaining()) return;
            resultType = (BattleResultType)_in.Read_byte();
            if(!_in.HasRemaining()) return;
            statisticsPOD = _in.Read_pod<BattleStatisticsPOD>(BattleStatisticsPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_awards = _in.Read_list_pod<ItemShowPOD>(ItemShowPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            testSettlementPOD = _in.Read_pod<BattleTestSettlementPOD>(BattleTestSettlementPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            levelSettlementPOD = _in.Read_pod<BattleLevelSettlementPOD>(BattleLevelSettlementPOD.DynamicFactory);
        }
		
		public BattleSettlementPOD Clone() {
            BattleSettlementPOD o = DynamicFactory();
            o.battleType = battleType;
            o.resultType = resultType;
            if (statisticsPOD != null) {
                o.statisticsPOD = statisticsPOD.Clone();
            }
            if (m_awards != null) {
                o.m_awards = m_awards.ConvertAll(o => o?.Clone());
            }
            if (testSettlementPOD != null) {
                o.testSettlementPOD = testSettlementPOD.Clone();
            }
            if (levelSettlementPOD != null) {
                o.levelSettlementPOD = levelSettlementPOD.Clone();
            }
            return o;
        }
        
        public void Clear() {
            battleType = default;
            resultType = default;
            statisticsPOD = default;
            m_awards = default;
            testSettlementPOD = default;
            levelSettlementPOD = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "BattleSettlementPOD [";
			str += "battleType=";
			str += battleType;
			str += ", resultType=";
			str += resultType;
			str += ", statisticsPOD=";
			str += statisticsPOD;
			str += ", awards=";
			str += m_awards.ToString<ItemShowPOD>();
			str += ", testSettlementPOD=";
			str += testSettlementPOD;
			str += ", levelSettlementPOD=";
			str += levelSettlementPOD;
			str += "]";
			return str;
		}
		
	}
}